﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.ComponentModel;

namespace FIFP.DashBoard.Model
{
    public class Unit : INotifyPropertyChanged
    {
        #region Variables
        private int unitID;
        private int parentUnitID;
        private string unitName;
        private string unitType;
        public List<Unit> ChildUnitList { get; set; }
        public bool IsNodeEnabled { get; set; }
        public string FluidType { get; set; }
        public string ProdInjType { get; set; }
        public SolidColorBrush UnitNameTextColor { get; set; }
        public int Level { get; set; }
        public List<Unit> TowerUnitList { get; set; }
        private double capacity;
        private double effectiveCapacity;
        private double realCapacity;
        private bool isBottleneck;        
        public bool hasMultipleParent { get; set; }
        public bool hasCommonTower { get; set; }

        public bool ByPassItemChecked { get; set; }
        public bool USOSSPItemChecked { get; set; }
        private int isModified = -1;
        public int GroupId { get; set; }
        
        #endregion

        #region Properties 
        private List<Unit> parentUnitList = new List<Unit>();
        public List<Unit> ParentUnitList
        {
            get { return parentUnitList; }
            set { parentUnitList = value; }
        }

        private List<int> parentUnitIDList = new List<int>();
        public List<int> ParentUnitIDList
        {
            get { return parentUnitIDList; }
            set { parentUnitIDList = value; }
        }

        public int UnitID
        {
            get { return unitID; }
            set { unitID = value;}
        }

        public int ParentUnitID
        {
            get { return parentUnitID; }
            set { parentUnitID = value; }
        }

        public string UnitName
        {
            get { return unitName; }
            set { unitName = value; }
        }

        public string UnitType
        {
            get { return unitType; }
            set { unitType = value; }
        }

        public double Capacity
        {
            get { return capacity; }
            set
            {
                double b = double.Parse(value.ToString("0.00"));
                //capacity = value; 
                capacity = b;
                onPropertyChanged(this, "Capacity");
            }
        }

        public double EffectiveCapacity
        {
            get { return effectiveCapacity; }
            set
            {
                double b = double.Parse(value.ToString("0.00"));
                effectiveCapacity = b;
                onPropertyChanged(this, "EffectiveCapacity");
            }
        }

        public double RealCapacity
        {
            get { return realCapacity; }
            set
            {
                double b = double.Parse(value.ToString("0.00"));
                realCapacity = b;
                //realCapacity = decimal.Round(realCapacity, 2);
                onPropertyChanged(this, "RealCapacity");
            }
        }

        public int IsModified
        {
            get { return isModified; }
            set { isModified = value; }
        }

        public bool IsBottleNeck
        {
            get { return isBottleneck; }
            set { isBottleneck = value; onPropertyChanged(this, "IsBottleNeck"); }
        }

        public override bool Equals(object obj)
        {
            Unit unit = obj as Unit; if (unit == null) return false;
            return (this.UnitName == unit.UnitName);
        }

        #endregion    
    
        // Declare the PropertyChanged event
        public event PropertyChangedEventHandler PropertyChanged;

        // OnPropertyChanged will raise the PropertyChanged event passing the source property that is being updated.
        private void onPropertyChanged(object sender, string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
